package es.ceura.wilder.datastructures;

import java.nio.ByteBuffer;
import java.util.Arrays;

/**
 *
 * @author Jorge Madrid
 */
public class Message {

    private int maxBufferSize;
    private int bufferSize;
    ByteBuffer dataBuffer;

    public Message(int inputSize) {
        maxBufferSize = inputSize;
        bufferSize = 0;
        dataBuffer = ByteBuffer.allocate(maxBufferSize);
    }

    public void appendData(byte[] inputData, int read) {
        dataBuffer.put(inputData, bufferSize, read);
        bufferSize += read;
        //Clean the buffer...
        Arrays.fill(inputData, 0, read, (byte) 0);
    }

    public int getSize() {
        return bufferSize;
    }

    public int maxSize() {
        return maxBufferSize;
    }
    
    public byte[] toArray(){
        return dataBuffer.array();
    }
}
